<template>
  <div class="goods-list">
    <el-card shadow="never">
      <el-form ref="searchForm" :model="form" label-width="100px" label-position="right">
        <el-row>
          <el-col :md="8">
            <el-form-item label="订单编号">
              <el-input
                v-model="form.requestOrderNo"
                clearable
                placeholder="请输入订单编号"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="用户姓名">
              <el-input
                v-model="form.userName"
                clearable
                placeholder="请输入用户姓名"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="用户手机号">
              <el-input
                v-model="form.userPhone"
                clearable
                placeholder="请输入用户手机号"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="订单状态">
              <el-select v-model="form.status" clearable placeholder="请选择订单状态">
                <el-option v-for="item in statusData" :key="item.value" :label="item.name" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="下单日期">
              <el-date-picker
                v-model="times"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item align="right">
              <el-button type="primary" @click="getDemandOrderList()">查 询</el-button>
              <el-button plain @click="resetForm()">重 置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        v-loading="loading"
        :data="tableData"
        stripe
        :header-cell-style="{background:'#f2f3f5',color:'#606266'}"
        class="table-data"
      >
        <el-table-column type="selection" align="center" width="55" />
        <el-table-column prop="id" label="编号" align="center" :show-overflow-tooltip="true" min-width="60" />
        <el-table-column prop="requestOrderNo" label="订单编号" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="title" label="用户信息" align="center" :show-overflow-tooltip="true" min-width="180">
          <template slot-scope="scope">
            <div class="infor"> <i class="icon el-icon-s-custom" />{{ `姓名：${scope.row.userName} ` }}</div>
            <div class="infor"><i class="icon el-icon-phone" />{{ `电话： ${scope.row.userPhone}` }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="用户地址" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="orderCategoryName" label="订单类型" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="orderAmount" label="订单金额" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="grabStatus" label="订单状态" align="center" :show-overflow-tooltip="true" min-width="150">
          <template slot-scope="scope">
            <span> {{ scope.row.grabStatus == 0 ? '待抢' : '已抢' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="下单日期" align="center" :show-overflow-tooltip="true" min-width="180">
          <template slot-scope="scope">
            <span> {{ formatTimes(scope.row.gmtCreate,"YYYY/MM/DD hh:mm:ss") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="$showNoAuthMsg(scope)">订单详情</el-button>
            <el-button type="text" size="small" @click="$showNoAuthMsg()">指派师傅</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          :page-size="page.pageSize"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :current-page.sync="page.pageNo"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
    <AppointWorkerDialog v-if="appointWorkerDialog" :appoint-worker-dialog="appointWorkerDialog" @closeDialog="closeDialog" />
  </div>
</template>

<script>
import AppointWorkerDialog from './components/appointWorkerDialog'
import { statusData } from './orderConfig'
import { getDemandOrderList } from '@/api/order'
import { formatTimes } from '@/utils'
export default {
  components: { AppointWorkerDialog },
  data() {
    return {
      formatTimes,
      form: {},
      statusData,
      appointWorkerDialog: false,
      tableData: [],
      loading: false,
      times: [],
      page: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  computed: {
  },
  mounted() {
    this.getDemandOrderList()
  },
  methods: {
    async getDemandOrderList() {
      try {
        this.loading = true
        const parmas = {
          ...this.form,
          beginDate: this.times && this.times.length > 0 ? this.times[0] : '',
          endDate: this.times && this.times.length > 0 ? this.times[1] : '',
          ...this.page
        }
        const res = await getDemandOrderList(parmas)
        this.loading = false
        this.tableData = res.objects
        this.page.total = res.total
      } catch (error) {
        this.loading = false
        console.log(error)
      }
    },
    // 重置搜索
    resetForm() {
      this.$nextTick(() => {
        this.form = {}
        this.times = []
      })
    },
    // 跳转到订单详情
    linkOrderDetail(row) {
      this.$router.push({
        path: '/order/detail',
        query: {
          id: row.id
        }
      })
    },
    // 指派师傅
    appointWorker(row) {
      this.appointWorkerDialog = true
    },
    closeDialog() {
      this.appointWorkerDialog = false
    },
    // 切换条
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getDemandOrderList()
    },
    // 切换页
    handleCurrentChange(val) {
      this.page.pageNo = val
      this.getDemandOrderList()
    }
  }
}
</script>
<style lang="scss" scoped>
.el-select{
  width: 100%;
}
.table-data{
  margin: 30px 0px;
  .infor{
    padding: 5px 0px;
    .icon{
      margin: 0 6px;
    }
  }
}
.el-date-editor{
  width: 100%;
}
.pagination{
  text-align: right;
}
</style>
